import { Inject, Injectable } from '@angular/core';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { API_CONFIG, ServicesModule } from '../services.module';
import { Observable, map } from 'rxjs';
import {Banner,Result} from '../../data_type/common.type';

@Injectable({
  providedIn: ServicesModule
})
export class HomeService {



  searchHive(searchQuery: string,tablePage: number, pageSize: number): Observable<Result> {
    let body = {
      'tablePage': tablePage.toString(),
      'pageSize': pageSize.toString(),
      'table': searchQuery,
      'tablePath': "test.db"
    };
    let headers = new HttpHeaders().set('Content-Type', 'application/json');
    return this.http.post<Result>(this.uri + 'rx/search/readSeq', body, { headers: headers })
      .pipe(map((res: Result) => res));
  }

  search(searchQuery: string,page: number, pageSize: number): Observable<any[]> {
    return this.http.get<{ banners: any[] }>(this.uri + 'banner').pipe(map(
      (res: { banners: any[] }) => res.banners
    ));
  }

  getPagedData(page: number, pageSize: number) {
    return this.http.get(this.uri + 'data', {
      params: {
        page: page.toString(),
        pageSize: pageSize.toString()
      }
    });
  }

  constructor(private http: HttpClient, @Inject(API_CONFIG) private uri: string) { }
}
